#!/usr/bin/env python
#coding:utf-8

import cgi
import sqlite3
import cgitb;cgitb.enable()

conn = sqlite3.connect('input.db')
curs = conn.cursor()

print "Content-type: text/html\n"

print """\
<h1>信息查询</h1>
<a href="/wiki/add/input.html" >Input</a>|
<a href="/wiki/add/list.py" >List</a>| 
<a href="/wiki/add/query.py" >Query</a><br />
<hr>
"""
print """\
<html><head><title>Query</title></head><body>
<form method="post" action="query.py">
输入要搜索的人名：<input type="text" name="keyword">
<input type="submit" value="搜索">
</form>"""

form = cgi.FieldStorage()
if form.has_key("keyword"):
    query = "select * from address where name='%s'" % cgi.escape(form.getvalue("keyword","None"))
    curs.execute(query)
    for i in curs.fetchall():
        for a in i:
            print a,
        print "<br />"
    #print 
else:
    print "<em>请输入人名！</em>"

print "</body></html>"
